package com.teach.service.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.teach.commons.Id;
import com.teach.entity.Report;
import com.teach.exception.CodeException;
import com.teach.mapper.ReportMapper;
import com.teach.service.ReportService;
@Service
public class ReportServiceImpl implements ReportService {
	@Autowired
	private ReportMapper mapper;
	@Autowired
	private Id id;
	@Override
	public void insertReport(Report report) throws CodeException {
		// TODO Auto-generated method stub
		report.setReportId(id.nextId());
		report.setReportHandle(false);
		report.setReportTime(new Date());
		mapper.insertSelective(report);
	}

	@Override
	public PageInfo<Report> pageReport(int current,int rowMax) throws CodeException {
		// TODO Auto-generated method stub
		return PageHelper.startPage(current, rowMax).doSelectPageInfo(()->mapper.select());
	}

	@Override
	public void modifyReport(Long reportId) throws CodeException {
		// TODO Auto-generated method stub
		Report report=mapper.selectByPrimaryKey(reportId);
		report.setReportHandle(true);
		mapper.updateByPrimaryKeySelective(report);
	}

	@Override
	public Report get(Long reportId) {
		// TODO Auto-generated method stub
		return mapper.selectByPrimaryKey(reportId);
	}

}
